<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录页面</title>
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/blog-login.css">
    <script src="js/jquery.min.js"></script>
</head>

<body>
    <!--导航栏-->
    <div class="nav">
        <!--头像-->
        <img src="css/cat.jpg" alt="">
        <span>博客系统</span>
        <!--使用空白元素，进行占位-->
        <div class="spaner">
            <span> </span>
        </div>
        <a href="blog_list.html">主页</a>
        <a href="blog_add.html">写博客</a>
        <a href="blog_sign.html">注册</a>
    </div>
    <!--登录页面-->
    <div class="login-content">
        <!--用form表单构造请求-->
            <div class="login-dialog">
                <h3>登录</h3>
                <div class="row">
                    <span>用户名</span>
                    <input type="text" id="username">
                </div>
                <div class="row">
                    <span>密码</span>
                    <input type="password" id="password">
                </div>
                <div class="row">
                    <button id="submit" onclick="mysub()">提交</button>
                </div >
            </div>
    </div>
    <script>
        function mysub(){
            //非空检查
            var username=jQuery("#username");
            var password=jQuery("#password");
            if(username.val().trim()==""){
                alert("请输入用户名");
                username.focus();
                return false;
            }
            if(password.val().trim()==""){
                alert("请输入密码");
                password.focus();
                return false;
            }
            //请求数据发给后端
            jQuery("#submit").attr("disable","disable");
            jQuery.ajax({
                url:"user/login",
                type:"post",
                data:{
                    "username":username.val().trim(),
                    "password":password.val().trim()
                },
                success:function(res){
                    if(res.code==200&&res.data==1){
                        alert("登录成功"),
                        location.href="blog_list.html";
                    }else{
                        alert("登录失败！请重新登录"+res.msg)
                    }

                }

            });
        }
    </script>
</body>

</html>